Skip to content

Conversation

@lukaszzazulak
Copy link
Contributor

Resolve references for async v3

import * as openapi3_1AdapterYaml from '@swagger-api/apidom-parser-adapter-openapi-yaml-3-1';
import * as asyncapi2AdapterJson from '@swagger-api/apidom-parser-adapter-asyncapi-json-2';
import * as asyncapi2AdapterYaml from '@swagger-api/apidom-parser-adapter-asyncapi-yaml-2';
import * as asyncapi3AdapterYaml from '@swagger-api/apidom-parser-adapter-asyncapi-yaml-3';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we add JSON parser adapter as well?

if (contentLanguage.namespace === 'asyncapi' && contentLanguage.format === 'JSON') {
if (
contentLanguage.namespace === 'asyncapi' &&
(contentLanguage.version?.startsWith('2.') || !contentLanguage.version) &&
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will the first condition not be enough?

Suggested change
(contentLanguage.version?.startsWith('2.') || !contentLanguage.version) &&
contentLanguage.version?.startsWith('2.') &&

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

unfortunately there were tests failing without additional condition

({ hasBasicElementProps, isElementType, primitiveEq, hasClass }) => {
return (element: unknown): element is AsyncApi2Element =>
element instanceof AsyncApi2Element ||
(element instanceof AsyncApi2Element && element.constructor === AsyncApi2Element) ||
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see that other predicates for the root element do not have this - is there some issue when it's not here?

Suggested change
(element instanceof AsyncApi2Element && element.constructor === AsyncApi2Element) ||
(element instanceof AsyncApi2Element ||

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, the method returns true for the AsyncApi3 as well which is unwanted.

return !parent ? mergedElement : false;
}

public async ChannelItemElement(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we will never visit here because ChannelItemElement does not exist in AsyncAPI 3.x. We also don't need additional handling for ChannelElement - it was needed for ChannelItemElement because it had the $ref field, while it does not exist for ChannelElement. As such, I think this can be removed.

});
refSet.add(immutableReference);
}
// eslint-disable-next-line no-debugger
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// eslint-disable-next-line no-debugger

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants